//
//  UIView+FK.m
//  NeteaseEdu
//
//  Created by xmc06 on 16/9/27.
//  Copyright © 2016年 zmosa. All rights reserved.
//

#import "UIView+FK.h"

@implementation UIView (FK)

- (void)setFk_x:(CGFloat)fk_x
{
    CGRect frame = self.frame;
    frame.origin.x = fk_x;
    self.frame = frame;
}

- (CGFloat)fk_x
{
    return self.frame.origin.x;
}

- (void)setFk_y:(CGFloat)fk_y
{
    CGRect frame = self.frame;
    frame.origin.y = fk_y;
    self.frame = frame;
}

- (CGFloat)fk_y
{
    return self.frame.origin.y;
}

- (void)setFk_width:(CGFloat)fk_width
{
    CGRect frame = self.frame;
    frame.size.width = fk_width;
    self.frame = frame;
}

- (CGFloat)fk_width
{
    return self.frame.size.width;
}

- (void)setFk_height:(CGFloat)fk_height
{
    CGRect frame = self.frame;
    frame.size.height = fk_height;
    self.frame = frame;
}

- (CGFloat)fk_height
{
    return self.frame.size.height;
}

- (void)setFk_size:(CGSize)fk_size
{
    CGRect frame = self.frame;
    frame.size = fk_size;
    self.frame = frame;
}

- (CGSize)fk_size
{
    return self.frame.size;
}

- (void)setFk_centerX:(CGFloat)fk_centerX
{
    CGPoint center = self.center;
    center.x = fk_centerX;
    self.center = center;
}

- (CGFloat)fk_centerX
{
    return self.center.x;
}

- (void)setFk_centerY:(CGFloat)fk_centerY
{
    CGPoint center = self.center;
    center.y = fk_centerY;
    self.center = center;
}

- (CGFloat)fk_centerY
{
    return self.center.y;
}

- (BOOL)fk_isShowingOnKeyWindow
{
    // 主窗口
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    
    // 以主窗口左上角为坐标原点, 计算self的矩形框
    CGRect newFrame = [keyWindow convertRect:self.frame fromView:self.superview];
    CGRect winBounds = keyWindow.bounds;
    
    // 主窗口的bounds 和 self的矩形框 是否有重叠
    BOOL intersects = CGRectIntersectsRect(newFrame, winBounds);
    
    return !self.isHidden && self.alpha > 0.01 && self.window == keyWindow && intersects;
}

@end
